<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            color: #333;
            font-size: 16px;
        }
        
        a {
            color: #333;
            text-decoration: none;
        }
        
        table {
            width: 400px;
            margin: 0 auto;
            padding: 20px;
            background: url(banner-re.jpg) no-repeat;
            background-size: 100% 100%;
        }
        
        input {
            outline: none;
            border: 1px solid grey;
            border-radius: 4px;
        }
        
        tr {
            display: inline-block;
            margin-bottom: 4px;
        }
        
        tr td {
            color: palegreen;
            cursor: pointer;
        }
        
        tr td:first-child {
            width: 80px;
        }
        
        .login,
        button {
            box-sizing: border-box;
            display: inline-block;
            width: 50px;
            height: 30px;
            border: 1px solid #999;
            border: 1px solid #999;
            background-color: moccasin;
            line-height: 30px;
            text-align: center;
            border-radius: 4px;
            margin-top: 8px;
            opacity: 1;
            transition: all .5s;
            cursor: pointer;
            font-size: 16px;
        }
        
        .login:hover,
        button:hover {
            opacity: 0.7;
            transform: scale(1.05);
            color: steelblue;
        }
        
        button {
            margin-left: 0;
        }
        
        .last {
            margin-top: 10px;
        }
        
        h2 {
            color: skyblue;
        }
        
        label {
            cursor: pointer;
        }
    </style>
</head>

<body>

    <table>
        <caption>
            <h2>用户注册</h2>
        </caption>
        <tbody>
            <tr>
                <td>
                    <label for="username">用户名:</label>
                </td>
                <td>
                    <input type="text" id="username">
                    <!-- <span id="name" class="inner"></span> -->
                </td>
            </tr>
            <tr>
                <td>
                    <label for="password">密码:</label>
                </td>
                <td>
                    <input type="password" id="password">
                    <!-- <span id="word" class="inner"></span> -->
                </td>
            </tr>
            <tr>
                <td>
                    <label for="repassword">确认密码:</label>
                </td>
                <td>
                    <input type="password" id="repassword">
                </td>
            </tr>
            <tr class="last">
                <td>
                    <button id="register">注册</button>
                </td>
                <td>
                    <a href="login.html" class="login">登录</a>
                </td>
            </tr>
        </tbody>

    </table>

</body>

</html>
<script src="jquery.min.js"></script>
<script>
    $("#register").click(function() {
        let username = $("#username").val();
        let password = $("#password").val();
        let repassword = $("#repassword").val();
        if (username === "" && password === "" && repassword === "") {
            alert("空");
            return;
        }
        if (password !== repassword) {
            alert("不一致");
            return;
        }
        if ((username && password && repassword) && (repassword === password)) {
            $.ajax({
                url: "http://10.35.164.246:8080/register",
                data: {
                    username: username,
                    password: password,
                },
                success: function(data) {
                    if (data === "success") {
                        alert("您的账号注册成功");
                        location.href = "http:10.35.164.246/registPage/login.html";
                    }
                    if (data === "exist") {
                        alert("您输入的用户名已存在！");
                    }
                }
            })
        }
    })
</script>